package me.shiqiang.im.service;

import me.shiqiang.im.dao.UserGroupsDao;
import me.shiqiang.im.domain.GroupProperties;
import me.shiqiang.im.domain.UserGroups;
import me.shiqiang.im.vo.GroupPropsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * Created by John on 2018/1/12
 */
@Service
public class UserGroupsService {

    @Autowired
    private UserGroupsDao userGroupsDao;

    public List<GroupPropsVo> getGroupList(Long userId) {
        UserGroups userGroups = userGroupsDao.findOne(userId);
        List<GroupPropsVo> vos = new ArrayList<>();
        if (userGroups != null) {
            GroupPropsVo groupPropsVo;
            for (GroupProperties groupProperties : userGroups.getGroups().values()) {
                groupPropsVo = new GroupPropsVo();
                groupPropsVo.setGroupId(groupProperties.getGroupId());
                groupPropsVo.setName(groupProperties.getName());
                groupPropsVo.setType(groupProperties.getType());
                groupPropsVo.setSubType(groupProperties.getSubType());
                groupPropsVo.setNoDisturb(groupProperties.getNoDisturb());
                vos.add(groupPropsVo);
            }
        }
        return vos;
    }
}
